﻿Imports System.Xml.Serialization
Imports System.ComponentModel
Imports Microsoft.VisualBasic.Strings

Public MustInherit Class SystemClass
    Implements INotifyPropertyChanged
    Implements IComparable

    Public Event PropertyChanged(ByVal sender As Object, ByVal e As PropertyChangedEventArgs) Implements INotifyPropertyChanged.PropertyChanged

    Private strName As String
    Private _intID As Integer
    'Private oApp As App

    Public Overridable Property Name() As String
        Get
            Return strName
        End Get
        Set(ByVal value As String)
            strName = value
            RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs("Name"))
        End Set
    End Property

    Public Property ID() As Integer
        Get
            Return _intID
        End Get
        Set(ByVal value As Integer)
            _intID = value
            RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs("ID"))
        End Set
    End Property

    Public Sub New()


    End Sub

    Public Sub OnPropertyChanged(ByVal Sender As Object, ByVal Args As PropertyChangedEventArgs)

        RaiseEvent PropertyChanged(Sender, Args)

    End Sub

    Public Overridable Function CompareTo(ByVal item As Object) As Integer Implements IComparable.CompareTo

        'Need to cycle through comparing characters and then return for Incoming compared to me
        ' -1 for Less than
        '  0 for equal
        '  1 for Greater

        Dim myName As String = CType(item, SystemClass).Name

        Dim maxChars As Integer
        If Len(myName) > Len(Me.Name) Then
            maxChars = Len(Me.Name)
        Else
            maxChars = Len(myName)
        End If

        Dim i As Integer
        For i = 1 To maxChars
            If Asc(Mid(myName, i, 1)) > Asc(Mid(Me.Name, i, 1)) Then
                Return 1
            ElseIf Asc(Mid(myName, i, 1)) < Asc(Mid(Me.Name, i, 1)) Then
                Return -1
            End If

        Next

        Return 0

    End Function

End Class
